package com.snow.useviewdemo.function2.viewfliper;

import android.os.Bundle;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.snow.useviewdemo.R;
import com.snow.useviewdemo.base.BaseActivity;
import com.snow.useviewdemo.databinding.ActivityUpMarqueeBinding;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhaoyingtao
 * Date: 2020/6/16
 * Describe:垂直滚动消息效果
 */
public class UPMarqueeActivity extends BaseActivity<ActivityUpMarqueeBinding> {

    @Override
    protected int getLayoutId() {
        return R.layout.activity_up_marquee;
    }

    @Override
    protected void setViewData(Bundle savedInstanceState) {
        addTextViews();
        addCustomViews();
    }

    private void addCustomViews() {
        List<View> views = new ArrayList<>();
        List<String> linesList = new ArrayList<>();
        linesList.add("上的讲话精神的");
        linesList.add("ewtetkwfdskajhsag");
        linesList.add("低功耗嘎嘎卡嘎解决");
        linesList.add("UK厉害克雷登斯嘎嘎嘎");
        for (int i = 0; i < linesList.size(); i++) {
            View view = LayoutInflater.from(this).inflate(R.layout.view_custom_marquee, null);
            TextView textView = view.findViewById(R.id.tv_quee);
            textView.setText(linesList.get(i));
            views.add(view);
        }
        mBinding.viewUPMarqueeView.setViews(views);
    }

    private void addTextViews() {
        List<TextView> textViews = new ArrayList<>();
        List<String> linesList = new ArrayList<>();
        linesList.add("上的讲话精神的");
        linesList.add("ewtetkwfdskajhsag");
        linesList.add("低功耗嘎嘎卡嘎解决");
        linesList.add("UK厉害克雷登斯嘎嘎嘎");
        for (String string : linesList) {
            TextView text = new TextView(this);
            text.setMaxLines(1);
            text.setEllipsize(TextUtils.TruncateAt.END);
            text.setGravity(Gravity.CENTER_VERTICAL);
            text.setTextSize(TypedValue.COMPLEX_UNIT_SP, 28);
            text.setText(string);
            textViews.add(text);
            text.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //点击事件
                }
            });
        }
        mBinding.famousUPMarqueeView.setViews(textViews);
    }

}
